﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LinqToTwitter;

namespace Twilter
{



    public partial class TwilterMainWindow : Form
    {
        public TwilterMainWindow()
        {
            InitializeComponent();
        }

        private void publicTimelineButton_Click(object sender, EventArgs e)
        {
          try
            {
          
                var publicTweets =  GlobalInfo.LinqBackendCtx.GetPublicTimeline(GlobalInfo.TwitterCtx);

                     publicTweets.ToList().ForEach(
                          tweet => myTextBox.Text = myTextBox.Text + tweet.User.Name + " : " + tweet.Text + Environment.NewLine);

            }
            catch (Exception)
            {
                MessageBox.Show("Mingi jama", "Viga");
            }

           
        }

        private void LoginButton_Click(object sender, EventArgs e)
        {

            GlobalInfo.TwitterUsername = twitterUsername.Text;
            GlobalInfo.TwitterPassword = twitterPassword.Text;
            LinqBackend myBackend = new LinqBackend();
            GlobalInfo.LinqBackendCtx = myBackend;
            try
            {
                myBackend.SignIn();
            }
            catch (Exception)
            {
                MessageBox.Show("Autoriseerimine eba6nnestus", "Viga");
            }

        }

    }
}
